/****************************************************************************
 *
 * Copyright (C) 2003-2008 Los Alamos National Security, LLC
 *                         Packet Analytics Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 2 as
 * published by the Free Software Foundation.  You may not use, modify or
 * distribute this program under any other version of the GNU General
 * Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 ****************************************************************************/
package nfse.gui.client.data;

import java.util.*;

import com.google.gwt.user.client.rpc.IsSerializable;

public class CriticalServerCollection  implements IsSerializable
{

	//private String[] dataTypes = {"ProofPoint","Netflow","Firewall","Snort"};
	
	private ArrayList dataTypes = new ArrayList();
	
	private HashMap ipCountRecordMap = new HashMap();
	
	
	
	public CriticalServerCollection()
	{
		
	}
	
	/**
	 * 
	 * @param rawDataMap - keyed by data type where each object is a hashmap of criticalServer objects keyed by IP
	 * @return
	 */
	public HashMap convertData(HashMap rawDataMap)
	{
		Iterator it = rawDataMap.keySet().iterator();
		while (it.hasNext())
		{
			String dataType = (String)it.next();
			dataTypes.add(dataType);
			//This handles putting the criticalserver object in the record ArrayList in the right place
			//Without this missing counts for a data type would not be handled properly
            int dataTypeIndex = dataTypes.indexOf(dataType);           
			HashMap criticalServerMap = (HashMap)rawDataMap.get(dataType);
			Iterator localIt = criticalServerMap.keySet().iterator();
			while (localIt.hasNext())
			{
				String ip = (String)localIt.next();
				CriticalServer criticalServer = (CriticalServer)criticalServerMap.get(ip);
				
                if (ipCountRecordMap.get(ip) != null)
                {
                	ArrayList record = (ArrayList)ipCountRecordMap.get(ip);
                	record.add(dataTypeIndex,criticalServer);
                }
                else
                {
                	ArrayList record = new ArrayList();
                	record.add(dataTypeIndex,criticalServer);
                	ipCountRecordMap.put(ip, record);
                }
				
			}
		}
		return ipCountRecordMap;
	}

	public ArrayList getDataTypes()
	{
		return dataTypes;
	}

	public void setDataTypes(ArrayList dataTypes)
	{
		this.dataTypes = dataTypes;
	}
	
	
	
}
